# Create custom plot theme for charts.
theme_plot <- function(base_size = 23) {
theme_minimal(base_size = base_size) +
theme(
# Set title styling with custom font and color.
plot.title = element_text(face = "bold",
family = "outfit",
color = "#2d2a26",
size = base_size + 1,
hjust = 0.5
),
# Set subtitle with italic styling.
plot.subtitle = element_text(face = "italic",
family = "outfit",
color = "#51534a",
size = base_size - 1,
hjust = 0.5,
margin = margin(b = 0.5, unit = "cm")
),
# Set caption styling for source notes.
plot.caption = element_text(face = "italic",
family = "anonymous",
color = "#9b9e98",
size = base_size - 2
),
# Position legend at bottom.
legend.position = "bottom",
# Set grid line colors.
panel.grid.major = element_line(colour = "#d4d2cd"),
panel.grid.minor = element_line(colour = "#d4d2cd"),
# Style axis text and titles.
axis.text = element_text(face = "italic",
family = "anonymous",
size = base_size - 2,
hjust = 0.5
),
axis.title = element_text(face = "bold",
family = "anonymous",
size = base_size - 1,
hjust = 0.5
),
# Add spacing around axis titles.
axis.title.y = element_text(margin = margin(r = 0.5, unit = "cm")
),
axis.title.x = element_text(margin = margin(t = 0.5, unit = "cm")
),
# Style legend elements.
legend.title = element_text(face = "italic",
family = "anonymous",
size = base_size - 1,
hjust = 0.5
),
legend.title.position = "top",
legend.text = element_text(face = "italic",
family = "anonymous",
size = base_size - 2,
hjust = 0.5
),
# Set legend key dimensions.
legend.key.width = unit(2, "cm"),
legend.key.height = unit(0.5, "cm"),
# Set background colors for consistent appearance.
legend.background = element_rect(fill = "#f5f4f0", color = "#f5f4f0"),
plot.background = element_rect(fill = "#f5f4f0", color = "#f5f4f0"),
panel.background = element_rect(fill = "#f5f4f0", color = "#f5f4f0"),
# Add plot margins.
plot.margin = unit(c(1, 1, 1, 1), "cm")
)
}
# Create custom theme for maps.
# Similar to plot theme but removes axis elements.
theme_map <- function(base_size = 17) {
theme_minimal(base_size = base_size) +
theme(
plot.title = element_text(face = "bold",
family = "outfit",
color = "#2d2a26",
size = base_size + 1,
hjust = 0.5
),
plot.subtitle = element_text(face = "italic",
family = "outfit",
color = "#51534a",
size = base_size - 1,
hjust = 0.5,
margin = margin(b = 0.5, unit = "cm")
),
plot.caption = element_text(face = "italic",
family = "anonymous",
color = "#9b9e98",
size = base_size - 3
),
legend.position = "bottom",
# Remove grid lines for maps.
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
# Remove axis text and titles for maps.
axis.text = element_blank(),
axis.title = element_blank(),
legend.title = element_text(face = "italic",
family = "anonymous",
size = base_size - 1,
hjust = 0.5
),
legend.title.position = "top",
legend.text = element_text(face = "italic",
family = "anonymous",
size = base_size - 3,
hjust = 0.5
),
legend.key.width = unit(2, "cm"),
legend.key.height = unit(0.5, "cm"),
legend.background = element_rect(fill = "#f5f4f0", color = "#f5f4f0"),
plot.background = element_rect(fill = "#f5f4f0", color = "#f5f4f0"),
panel.background = element_rect(fill = "#f5f4f0", color = "#f5f4f0"),
plot.margin = unit(c(1, 1, 1, 1), "cm")
)
}